<!--processed-->
<link rel="stylesheet" href="/views/resolution/statistics/reply/detail/tmp.css">
<section id="reply-detail">
    <div class="breadcrumb">
        <i class="back iconfont icon-fanhui1" id="back"></i>
        <span>Resolution</span>
        <span class="interval">/</span>
        <span>Statistics</span>
        <span class="interval">/</span>
        <span>replay</span>
    </div>
    <div class="layout-processed feat-grid">

        <div class="data-box com-check">
            <table class="table-a">
                <thead class="t-head">
                <tr>
                    <th class="tc">序号</th>
                    <th>事业部</th>
                    <th>站点名称</th>
                    <th>账号名称</th>
                    <th>disputed</th>
                    <th>claim</th>
                    <th>chargeback</th>
                </tr>
                </thead>
                <tbody data-name="replyDetailList">

                </tbody>
            </table>
        </div>

    </div>
    <footer class="footer fx-row-b">
        <div>
            <span>Showing <span id="page-start">1</span> to <span id="page-end">20</span> of <span id="page-total">0</span> entries</span>
            <select name="page">
                <option value="10">10</option>
                <option value="20">20</option>
                <option value="30">30</option>
                <option value="50">50</option>
                <option value="100">100</option>
            </select>
            <span>records per page</span>
        </div>
        <section id="box-page"></section>
    </footer>
</section>

<!--渲染模板开始-->

<!--list data-->
<script id="reply-detail-list" type="text/html">
    {{each detail as v i}}
    <tr class="nth">
        <td class="tc"><span>{{i + $imports.count}}</span></td>
        <td>{{v.department_name}}</td>
        <td>{{v.site_name}}</td>
        <td>{{v.pp_account_email}}</td>
        <td>{{v.inquiry_cnt}}</td>
        <td>{{v.claim_cnt}}</td>
        <td>{{v.chargeback_cnt}}</td>
    </tr>
    {{/each}}
</script>


<!-- js -->
<script>

    $.extend(window.p,{
        page:1,
        num:20,
        total:0,
        pageObj:null,
        data:{
            inquiry:'asc',
            claim:'asc',
            chargeback:'asc',
            total:'asc'
        }
    });

    $(function(){

        init();

        function init(){

            if(com.getCookie('pageNum')) {
                p.num = com.getCookie("pageNum");
            }

            //默认分页显示
            $("select[name='page']").val(p.num);
            //返回
            $(".back").click(function(){
                window.history.go(-1);
            });

            //初始化请求数据列表
            request();

            //初始化分页
            initPage();

            //选择分页事件
            $("select[name='page']").on('change',function(){
                var val = $(this).val();
                com.setCookie('pageNum',val,720);
                p.num = val;
                request();
                //location.reload();
            });


        }

        function initPage(){
            p.pageObj = $("#box-page").comPage({
                total:p.total,
                pages:p.num,
                callback:function(page){
                    p.page = page;
                    request();
                }
            });
        }

        function renderLeftPage(){
            $("#page-total").html(p.total);
            $("#page-start").html((p.page-1)*p.num + 1);
            if(p.page === 1){
                $("#page-end").html(p.num);
            }else if(p.page == Math.ceil(p.total/p.num)) {
                $("#page-end").html(p.total);
            }else{
                $("#page-end").html(p.page*p.num);
            }
        }

        //请求列表
        function request(init){

            init && (p.page = 1);
            var loadObj = null;

            let startTime = com.getCookie('start_date');
            let endTime = com.getCookie('end_date');
            app.ajax({
                type:'post',
                url:app.api('/api/getCSDetail/' + p.urlPara),
                data:{
                    start_date:startTime,
                    end_date:endTime,
                    page:p.page,
                    page_nums : p.num,
                },
                beforeSend:function(){
                    loadObj = $.load({
                        insert:$(".layout-processed"),
                    });
                    $('footer').removeClass('hide')
                },
                success:function(res){
                    template.defaults.imports.count = (p.page-1)*p.num + 1;
                    if(res.code == 0){
                        var tmp = template('reply-detail-list', res.data);
                        $("[data-name='replyDetailList']").html(tmp);

                        p.total = res.data.total_cnt;
                        if(init){
                            p.pageObj.setPage(p.total,p.num,1);
                        }else{
                            p.pageObj.setPage(p.total,p.num);
                        }
                        renderLeftPage();

                    }else{
                        $.comMessage({
                            type:'warning',
                            text:res.msg,
                        });
                        $("[data-name='replyDetailList']").html('');
                        $('footer').addClass('hide')
                    }
                },
                complete:function(){
                    loadObj.close()
                }
            });
        }


    })


</script>